﻿Imports System.Data.SqlClient
Imports System.Configuration
Public Class frm_lophoc
    Dim tb As New DataTable
    Sub loadlh()
        Dim cmd As New SqlCommand("sp_lophoc_lenluoi", conn)
        cmd.CommandType = CommandType.StoredProcedure

        Dim da As New SqlDataAdapter(cmd)
        Dim tb1 As New DataTable
        tb = tb1
        da.Fill(tb1)
        dgv_lp.DataSource = tb1
    End Sub
    Private Sub frm_lophoc_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        loadlh()
    End Sub

    Private Sub cmd_tim_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_tim.Click
        If cbo_tim.SelectedIndex < 0 Then
            MsgBox("Vui lòng chọn mục cần tìm")
            Exit Sub
        End If


        If cbo_tim.SelectedIndex = 0 Then
            If txt_noidung.Text = "" Then
                MsgBox("Vui lòng nhập nội dung tìm kiếm!!!")
                Exit Sub
            End If
            tb.DefaultView.RowFilter = String.Format("MaLop = '{0}'", txt_noidung.Text)
            txt_noidung.Text = ""
        End If
        If cbo_tim.SelectedIndex = 1 Then
            If txt_noidung.Text = "" Then
                MsgBox("Vui lòng nhập nội dung tìm kiếm!!!")
                Exit Sub
            End If
            tb.DefaultView.RowFilter = String.Format("TenLop like '{0}%'", txt_noidung.Text)
            txt_noidung.Text = ""
        End If
        If cbo_tim.SelectedIndex = 2 Then

            loadlh()
        End If
    End Sub

    Private Sub cbo_tim_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbo_tim.SelectedIndexChanged
        If cbo_tim.SelectedIndex = 0 Then
            txt_noidung.Enabled = True
        End If
        If cbo_tim.SelectedIndex = 1 Then
            txt_noidung.Enabled = True
        End If
        If cbo_tim.SelectedIndex = 2 Then
            txt_noidung.Enabled = False
        End If
    End Sub
End Class